package net.chasing.androidbaseconfig.util;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;

public class ShapeUtils {

    public static GradientDrawable getRoundRectDrawable(int radius, int color) {
        return getRoundRectDrawable(radius, color, true, 0, true, true, true, true);
    }

    public static GradientDrawable getRoundRectDrawable(int radius, int color, boolean isLeftTop, boolean isRightTop,
                                                        boolean isLeftBottom, boolean isRightBottom) {
        return getRoundRectDrawable(radius, color, true, 0,
                isLeftTop, isRightTop, isLeftBottom, isRightBottom);
    }

    public static GradientDrawable getRoundStrokeDrawable(int radius, int color, int width) {
        return getRoundRectDrawable(radius, color, false, width, true, true, true, true);
    }

    private static GradientDrawable getRoundRectDrawable(int radius, int color, boolean isFill, int strokeWidth,
                                                         boolean isLeftTop, boolean isRightTop, boolean isLeftBottom, boolean isRightBottom) {
        //左上、右上、右下、左下的圆角半径
        float[] radiusGroup = {isLeftTop ? radius : 0, isLeftTop ? radius : 0,
                isRightTop ? radius : 0, isRightTop ? radius : 0,
                isLeftBottom ? radius : 0, isLeftBottom ? radius : 0,
                isRightBottom ? radius : 0, isRightBottom ? radius : 0};
        GradientDrawable drawable = new GradientDrawable();
        drawable.setCornerRadii(radiusGroup);
        drawable.setColor(isFill ? color : Color.TRANSPARENT);
        drawable.setStroke(isFill ? 0 : strokeWidth, color);
        return drawable;
    }
}
